package ltd.hanamaki.review.unit.testn_g.paramter.utils;

import java.io.*;
import java.util.ArrayList;
import java.util.List;

/**
 * @Author Hanamaki
 * @Version 1.0
 */
public class FileUtils {

    static FileInputStream fileInputStream;
    static InputStreamReader inputStreamReader;
    static BufferedReader bufferedReader;

    public static String[][] getFileContent(String filePath) {
        /* 定义一个 二维数组 */
        String[][] result = null;
        try {
            /* 从文件中 读取数据 */
            File file = new File(filePath);
            fileInputStream = new FileInputStream(file);
            /* 修改编码 */
            inputStreamReader = new InputStreamReader(fileInputStream, "utf-8");
            /* 加载 文件流 */
            bufferedReader = new BufferedReader(inputStreamReader);

            /* 定义一个集合来保存每一次的 数组数据 */
            List<String[]> list = new ArrayList<>();

            /* 定义一个变量来存取每一行的数据 */
            String contentLine = null;

            while ((contentLine = bufferedReader.readLine()) != null) {
                String[] split = contentLine.split(",");
                list.add(split);
            }
            /* 通过list  转为 二维数组 */
            result = new String[list.size()][];
            for (int i = 0; i < list.size(); i++) {
                result[i] = list.get(i);
            }


        } catch (Exception e) {
            e.printStackTrace();
        }finally {

            try {
                bufferedReader.close();
                inputStreamReader.close();
                fileInputStream.close();

            } catch (IOException e) {
                e.printStackTrace();
            }


        }

        return result;
    }



}